package com.controller;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

@RestController
@RequestMapping("/test/assert")
public class AssertController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AssertController.class);

    @GetMapping("/get")
    public String init(String userName) {
        RuntimeException e1 = new RuntimeException("test exception1");
        RuntimeException e2 = new RuntimeException("test exception2");
        RuntimeException e3 = new RuntimeException("test exception3");
        // 占位符号无效,可以打印错误栈
        LOGGER.error("error1 {}", e1);
        // 占位符号有效,可以打印错误栈
        LOGGER.error("error2 {}", userName, e2);
        // 无法打印错误栈, 当做普通参数处理，占位符号有效，e当做toString()处理了
        LOGGER.error("error3 {} {}", userName, e3);
        Assert.notNull(userName, "user name is null");
        return userName + ":" + UUID.randomUUID().toString();
    }
}
